<template>
	<div class="sw_system_container">
		<div class="system_config_item">
			<dl v-for="(item, index) in confifDictListData" :key="index">
				<dt>{{ item.content }}：</dt>
				<dd v-if="item.showType === '1'">
					<sw-number-input size="medium" v-model="item.name"></sw-number-input>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd v-else-if="item.showType === '2'">
					<el-switch v-model="item.name" :active-value="item.switch.active" :inactive-value="item.switch.inactive"></el-switch>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd v-else-if="item.showType === '3'">
					<el-switch v-model="item.name" :active-value="item.switch.active" :inactive-value="item.switch.inactive"></el-switch>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd v-else-if="item.showType === '4'">
					<el-switch v-model="item.name" :active-value="item.switch.active" :inactive-value="item.switch.inactive"></el-switch>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd v-else-if="item.showType === '5'">
					<el-switch v-model="item.name" :active-value="item.switch.active" :inactive-value="item.switch.inactive"></el-switch>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd v-else-if="item.showType === '6'">
					<el-switch v-model="item.name" :active-value="item.switch.active" :inactive-value="item.switch.inactive"></el-switch>
					<el-button size="medium" type="primary" @click="handleSaveData(item)">保存</el-button>
				</dd>
				<dd class="btn">
					<template></template>
				</dd>
			</dl>
		</div>
		<enum-drawer v-model="dictDrawer" :dict-id="dictId"></enum-drawer>
	</div>
</template>

<script>
import enumDrawer from '../dict/data';
import { getDictDefineList, updateDictDefine } from '@/api/system/tbSysDictDefinition';
export default {
	components: { enumDrawer },
	data() {
		return {
			confifDictList: [],
			numberList: [],
			switchList: [],
			enumerateList: [],
			radioList: [],
			textInputList: [],
			textAreaList: [],
			dictDrawer: false,
			dictId: ''
		};
	},
	computed: {
		confifDictListData() {
			return this.confifDictList.map((item) => {
				let obj = { ...item };
				let datas = JSON.parse(obj.configJson);
				obj['showType'] = datas.type;
				if (datas.type === '2') {
					obj['switch'] = datas.switch;
				} else if (datas.type === '4') {
					obj['options'] = datas.options;
				}
				return obj;
			});
		}
	},
	mounted() {
		this.getConfigDictList();
	},
	methods: {
		//获取字典定义
		async getConfigDictList() {
			let params = { page: 1, limit: 9999, isConfig: '1' };
			let result = await getDictDefineList(params).then((res) => res.data);
			if (result.code === '0') {
				this.confifDictList = result.data || [];
			}
		},

		//查看枚举
		handleLookEnum(data) {
			this.dictId = data.id;
			this.dictDrawer = true;
		},

		async handleSaveData(data) {
			let result = await updateDictDefine(data).then((res) => res.data);
			if (result.code === '0') {
				this.$showCustomMessage('success', `保存成功`);
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.system_config_item {
	padding: 16px 12%;
	dl {
		padding: 10px;
	}
}
</style>
